package com.yeren.ams.provider.serviceImpl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.alibaba.dubbo.config.annotation.Service;
import com.yeren.ams.api.model.ZTH;
import com.yeren.ams.api.service.ZthService;

@Service(retries = 0, timeout = 5000)
public class ZthServiceImpl implements ZthService {
	@Autowired
	@Qualifier("sessionFactory")
	SessionFactory sf;

	@Override
	public int findAll() {
		Query query = sf.openSession().createQuery("from ZTH");
		List<ZTH> emp = query.list();
		System.out.println("个数："+emp.size());
		return emp.size();
	}

	@Override
	public void save(ZTH zth) {
		Session session = sf.openSession();
		Transaction tx=null;
		try {
			tx = session.beginTransaction();
			session.save(zth);
			tx.commit();
		} catch (RuntimeException e) {
			tx.rollback();
			e.printStackTrace();
		}finally{
			session.close();
		}
		
	}

	@Override
	public int delete() {
		Query query = sf.openSession().createQuery("delete ZTH where id=1");
		int executeUpdate = query.executeUpdate();
		System.out.println(executeUpdate);
		return executeUpdate;
		
	}

	@Override
	public int update() {
		return 0;
		
	}

	@Override
	public int findById() {
		return 0;
		
	}

}
